home *** CD-ROM | disk | FTP | other *** search
/ Game Programming in C++ - Start to Finish / GameProgrammingS.iso / developer_install / CEGUISDK-0.4.1-VC6-STLport.exe / {app} / include / CEGUIXMLAttributes.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-08-21  |  9.3 KB  |  245 lines

  1. /************************************************************************
  2.     filename:   CEGUIXMLAttributes.h
  3.     created:    Sat Mar 12 2005
  4.     author:     Paul D Turner
  5. *************************************************************************/
  6. /*************************************************************************
  7.     Crazy Eddie's GUI System (http://www.cegui.org.uk)
  8.     Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
  9.  
  10.     This library is free software; you can redistribute it and/or
  11.     modify it under the terms of the GNU Lesser General Public
  12.     License as published by the Free Software Foundation; either
  13.     version 2.1 of the License, or (at your option) any later version.
  14.  
  15.     This library is distributed in the hope that it will be useful,
  16.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  18.     Lesser General Public License for more details.
  19.  
  20.     You should have received a copy of the GNU Lesser General Public
  21.     License along with this library; if not, write to the Free Software
  22.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  23. *************************************************************************/
  24. #ifndef _CEGUIXMLAttributes_h_
  25. #define _CEGUIXMLAttributes_h_
  26.  
  27. #include "CEGUIBase.h"
  28. #include "CEGUIString.h"
  29. #include <map>
  30.  
  31. #if defined(_MSC_VER)
  32. #    pragma warning(push)
  33. #    pragma warning(disable : 4251)
  34. #endif
  35.  
  36. // Start of CEGUI namespace section
  37. namespace CEGUI
  38. {
  39.     /*!
  40.     \brief
  41.         Class representing a block of attributes associated with an XML element.
  42.      */
  43.     class CEGUIEXPORT XMLAttributes
  44.     {
  45.     public:
  46.         /*!
  47.         \brief
  48.             XMLAttributes constructor.
  49.          */
  50.         XMLAttributes(void);
  51.  
  52.         /*!
  53.         \brief
  54.             XMLAttributes Destructor
  55.          */
  56.         virtual ~XMLAttributes(void);
  57.  
  58.         /*!
  59.         \brief
  60.             Adds an attribute to the attribute block.  If the attribute value already exists, it is replaced with
  61.             the new value.
  62.  
  63.         \param attrName
  64.             String object holding the name of the attribute to be added.
  65.  
  66.         \param attrValue
  67.             String object holding a string representation of the attribute value.
  68.  
  69.         \return
  70.             Nothing.
  71.          */
  72.         void add(const String& attrName, const String& attrValue);
  73.         
  74.         /*!
  75.         \brief
  76.             Removes an attribute from the attribute block.
  77.  
  78.         \param attrName
  79.             String object holding the name of the attribute to be removed.
  80.  
  81.         \return
  82.             Nothing.
  83.          */
  84.         void remove(const String& attrName);
  85.  
  86.         /*!
  87.         \brief
  88.             Return whether the named attribute exists within the attribute block.
  89.  
  90.         \param attrName
  91.             String object holding the name of the attribute to be checked.
  92.  
  93.         \return
  94.             - true if an attribute with the name \a attrName is present in the attribute block.
  95.             - false if no attribute named \a attrName is present in the attribute block.
  96.         */
  97.         bool exists(const String& attrName) const;
  98.  
  99.         /*!
  100.         \brief
  101.             Return the number of attributes in the attribute block.
  102.  
  103.         \return
  104.             value specifying the number of attributes in this attribute block.
  105.          */
  106.         size_t getCount(void) const;
  107.  
  108.         /*!
  109.         \brief
  110.             Return the name of an attribute based upon its index within the attribute block.
  111.  
  112.         \note
  113.             Nothing is specified about the order of elements within the attribute block.  Elements
  114.             may not, for example, appear in the order they were specified in the XML file.
  115.  
  116.         \param index
  117.             zero based index of the attribute whos name is to be returned.
  118.  
  119.         \return
  120.             String object holding the name of the attribute at the requested index.
  121.  
  122.         \exception IllegalRequestException  thrown if \a index is out of range for this attribute block.
  123.         */
  124.         const String& getName(size_t index) const;
  125.         
  126.         /*!
  127.         \brief
  128.             Return the value string of an attribute based upon its index within the attribute block.
  129.  
  130.         \note
  131.             Nothing is specified about the order of elements within the attribute block.  Elements
  132.             may not, for example, appear in the order they were specified in the XML file.
  133.         
  134.         \param index
  135.             zero based index of the attribute whos value string is to be returned.
  136.  
  137.         \return
  138.             String object holding the string value of the attribute at the requested index.
  139.  
  140.         \exception IllegalRequestException  thrown if \a index is out of range for this attribute block.
  141.         */
  142.         const String& getValue(size_t index) const;
  143.  
  144.         /*!
  145.         \brief
  146.             Return the value string for attribute \a attrName.
  147.  
  148.         \param attrName
  149.             String object holding the name of the attribute whos value string is to be returned
  150.  
  151.         \return
  152.             String object hilding the value string for attribute \a attrName.
  153.  
  154.         \exception UnknownObjectException   thrown if no attribute named \a attrName is present in the attribute block.
  155.          */
  156.         const String& getValue(const String& attrName) const;
  157.  
  158.         /*!
  159.         \brief
  160.             Return the value of attribute \a attrName as a string.
  161.  
  162.         \param attrName
  163.             String object holding the name of the attribute whos value is to be returned.
  164.  
  165.         \param def
  166.             String object holding the default value to be returned if \a attrName does not exist in the attribute block.
  167.             For some parsers, defaults can be gotten from schemas and such like, though for others this may not be desired
  168.             or possible, so this parameter is used to ensure a default is available in the abscence of other mechanisms.
  169.  
  170.         \return
  171.             String object containing the value of attribute \a attrName if present, or \a def if not.
  172.          */
  173.         const String& getValueAsString(const String& attrName, const String& def = "") const;
  174.  
  175.         /*!
  176.         \brief
  177.             Return the value of attribute \a attrName as a boolean value.
  178.  
  179.         \param attrName
  180.             String object holding the name of the attribute whos value is to be returned.
  181.  
  182.         \param def
  183.             bool value specifying the default value to be returned if \a attrName does not exist in the attribute block.
  184.             For some parsers, defaults can be gotten from schemas and such like, though for others this may not be desired
  185.             or possible, so this parameter is used to ensure a default is available in the abscence of other mechanisms.
  186.  
  187.         \return
  188.             bool value equal to the value of attribute \a attrName if present, or \a def if not.
  189.  
  190.         \exception IllegalRequestException  thrown if the attribute value string coul dnot be converted to the requested type.
  191.         */
  192.         bool getValueAsBool(const String& attrName, bool def = false) const;
  193.         
  194.         /*!
  195.         \brief
  196.             Return the value of attribute \a attrName as a integer value.
  197.  
  198.         \param attrName
  199.             String object holding the name of the attribute whos value is to be returned.
  200.  
  201.         \param def
  202.             integer value specifying the default value to be returned if \a attrName does not exist in the attribute block.
  203.             For some parsers, defaults can be gotten from schemas and such like, though for others this may not be desired
  204.             or possible, so this parameter is used to ensure a default is available in the abscence of other mechanisms.
  205.  
  206.         \return
  207.             integer value equal to the value of attribute \a attrName if present, or \a def if not.
  208.         
  209.         \exception IllegalRequestException  thrown if the attribute value string coul dnot be converted to the requested type.
  210.         */
  211.         int getValueAsInteger(const String& attrName, int def = 0) const;
  212.         
  213.         /*!
  214.         \brief
  215.             Return the value of attribute \a attrName as a floating point value.
  216.  
  217.         \param attrName
  218.             String object holding the name of the attribute whos value is to be returned.
  219.  
  220.         \param def
  221.             float value specifying the default value to be returned if \a attrName does not exist in the attribute block.
  222.             For some parsers, defaults can be gotten from schemas and such like, though for others this may not be desired
  223.             or possible, so this parameter is used to ensure a default is available in the abscence of other mechanisms.
  224.  
  225.         \return
  226.             float value equal to the value of attribute \a attrName if present, or \a def if not.
  227.  
  228.         \exception IllegalRequestException  thrown if the attribute value string coul dnot be converted to the requested type.
  229.         */
  230.         float getValueAsFloat(const String& attrName, float def = 0.0f) const;
  231.  
  232.     protected:
  233.         typedef std::map<String, String> AttributeMap;
  234.         AttributeMap    d_attrs;
  235.     };
  236.  
  237. } // End of  CEGUI namespace section
  238.  
  239.  
  240. #if defined(_MSC_VER)
  241. #    pragma warning(pop)
  242. #endif
  243.  
  244. #endif  // end of guard _CEGUIXMLAttributes_h_
  245.